/*
 * Copyright 2021 MindMotion Microelectronics Co., Ltd.
 * All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <stdint.h>
#include <stdio.h>

#include "board_init.h"
#include "at_server.h"

extern const at_adapter_t at_adapter;
extern const at_cmd_t at_cmd_at;
extern const at_cmd_t at_cmd_servo;
const at_cmd_t * at_cmd_list[]=
{
    &at_cmd_at,
    &at_cmd_servo
};

at_server_t at_server_local;

void app_servo_ctrl_init(void);

/*
 * Functions.
 */

int main(void)
{
    BOARD_Init();
    //printf("\r\ntim_output_compare_pwm.\r\n");

    /* Setup the timer. */
    app_servo_ctrl_init();
    
    //app_servo_pwm_value = 250;
    
        /* at server initialization. */
    at_server_init(&at_server_local,(at_adapter_t *)&at_adapter);
    /* set the at command list for at server. */
    at_server_set_cmd_list( &at_server_local, (at_cmd_t **)at_cmd_list, sizeof(at_cmd_list)/sizeof(* at_cmd_list));

    while (1)
    {
        at_server_task(&at_server_local); /* loop the at server task. */
    }

#if 0
    while (1)
    {
        //getchar();
        /* Update duty cycle. */
        app_servo_pwm_value = app_servo_pwm_value + 50;
        if (app_servo_pwm_value > 1250)
        {
            app_servo_pwm_value = 250;
        }
        
        for (uint32_t i = 0u; i < APP_SERVO_PWM_NUM; i++)
        {
            TIM_PutChannelValue(servo_pwm_ctrl_objs[i].port, servo_pwm_ctrl_objs[i].channel, app_servo_pwm_value);
            //printf("PWM value: %u\r\n", (unsigned)app_servo_pwm_value);
        }
    }
#endif
}


/* EOF. */

